package com.cloudcc.mobile.adapter;

import android.content.Context;
import android.provider.CallLog;
import android.text.TextUtils;

import com.cloudcc.cloudframe.adapter.CommonAdapter;
import com.cloudcc.cloudframe.adapter.ViewHolder;
import com.cloudcc.cloudframe.util.DateUtils;
import com.cloudcc.mobile.R;
import com.cloudcc.mobile.entity.CallLogEntity;

/**
 * Created by lin on 2017/6/2.
 *
 * 通话记录listview的item
 */

public class CallLogAdapter extends CommonAdapter<CallLogEntity> {
    public CallLogAdapter(Context mContext) {
        super(mContext);
    }

    @Override
    public void convert(ViewHolder holder, CallLogEntity entiy) {
        if(entiy.name == null || entiy.name.equals("")){
            holder.setText(R.id.call_log_item_name , entiy.number);
        }else{
            holder.setText(R.id.call_log_item_name , entiy.name);
        }
        holder.setText(R.id.call_log_item_longtime , DateUtils.howMuchDay(mContext , entiy.date));
        holder.setText(R.id.call_log_item_time , DateUtils.getHHMMTime(entiy.date));
        switch (entiy.match){
            case  1://完全匹配
                holder.setText(R.id.call_log_item_match , mContext.getString(R.string.call_log_dialog_match_success));
                break;
            case  4:
            case  2://多个匹配
                holder.setText(R.id.call_log_item_match , mContext.getString(R.string.call_log_dialog_match_more));
                break;
            case  3://不匹配
                holder.setText(R.id.call_log_item_match , mContext.getString(R.string.call_log_dialog_match_faile));
                break;
        }

        switch (entiy.type){
            case  CallLog.Calls.INCOMING_TYPE://打入
                holder.setSrc(R.id.call_log_type_iv , R.drawable.callhistory_callin);
                break;
            case  CallLog.Calls.OUTGOING_TYPE://打出
                holder.setSrc(R.id.call_log_type_iv , R.drawable.callhistory_exhale);
                break;
            case  CallLog.Calls.MISSED_TYPE://未接
                holder.setSrc(R.id.call_log_type_iv , R.drawable.callhistory_notconnected);
                break;
        }

    }

    @Override
    public int getLayoutId() {
        return R.layout.adapter_call_log;
    }
}
